<template>
  <app-dialog v-model="show" width="600px" title="标记" @open="handleOpen">
    <el-form :model="formData" label-width="130px" label-position="right" style="width: 70%; margin: 0 auto">
      <el-form-item label="输赢：">
        <el-radio-group v-model="formData.is_win" @change="changeiswin()">
          <el-radio :value="1">输</el-radio>
          <el-radio :value="2">赢</el-radio>
          <el-radio :value="3">走</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-if="formData.is_win == 1" label="不含本金(虚数)：">
        <el-input-number v-model="formData.win_back" style="width: 200px" controls-position="right" />
      </el-form-item>
      <el-form-item v-else label="本金(虚数)：">
        <el-input
          v-model="formData.win_back"
          :disabled="formData.is_win == 3"
          style="width: 200px"
          controls-position="right"
        />
      </el-form-item>
      <el-form-item label="结算状态：">
        <el-radio-group v-model="formData.check_status">
          <el-radio :value="1">已结算</el-radio>
          <el-radio :value="0">未结算</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="交收状态：">
        <el-radio-group v-model="formData.is_settlement">
          <el-radio :value="2">已交收</el-radio>
          <el-radio :value="1">未交收</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>

    <template #footer>
      <el-button @click="handleClose">取消</el-button>
      <el-button type="primary" @click="handleSubmit">确定</el-button>
    </template>
  </app-dialog>
</template>

<script setup>
import { http } from '@/utils/http'
import { ElMessage } from 'element-plus'
const show = defineModel({ type: Boolean })
const emits = defineEmits(['change'])
const getlistData = inject('getlistData');
const props = defineProps({
  data: Object,
})
const formData = ref({
  is_win: 1,
  win_back: 10000,
  check_status: 1,
  is_settlement: 2,
})

const changeiswin = () => {
  if (formData.value.is_win == 1) {
    formData.value.win_back = 10000
  } else if (formData.value.is_win == 2) {
    formData.value.win_back = 50
  } else {
    formData.value.win_back = 0
  }
}

const handleOpen = () => {
  formData.value.order_id = props.data.id
  formData.value.is_win = props.data.is_win == 0 ? 1 : props.data.is_win
  formData.value.win_back = props.data.win_back
  formData.value.check_status = props.data.check_status
  formData.value.is_settlement = props.data.is_settlement == 0 ? 1 : props.data.is_settlement
}

const handleClose = () => {
  show.value = false
}

const handleSubmit = () => {
  console.log(formData.value)
  if (formData.value.is_win == 1 && formData.value.win_back > 0) {
    formData.value.win_back = -formData.value.win_back
  }
  if (formData.value.is_win == 2 && formData.value.win_back < 0) {
    formData.value.win_back = Math.abs(formData.value.win_back)
  }
  const onSuccess = () => {
    ElMessage.success('操作成功')
    handleClose()
    getlistData()
  }

  http({
    method: 'POST',
    url: "/order/order_update_tab",
    data: formData.value,
  }).then(onSuccess)
}
</script>

<style lang="scss" scoped>
</style>